{{extend 'layout.html'}}
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1.0', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChartFav);
    google.setOnLoadCallback(drawChartSpam);
    google.setOnLoadCallback(drawChartCat);
    
    function drawChartCat() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Category');
        data.addColumn('number', 'Count');        
        
        {{ for c in category: }}
        data.addRow([ '{{=c.category}}' , {{=c.count}} ])
        {{pass}}
               
        // Set chart options
        var options = {'title':'Favorite feature',
                       'width':300,
                       'height':200};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div_cat'));
        chart.draw(data, options);
      }
    
      
    function drawChartFav() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Feature');
        data.addColumn('number', 'Count');        
        
        {{ for f in fav: }}
        data.addRow([ '{{=f.feature}}' , {{=f.count}} ])
        {{pass}}
               
        // Set chart options
        var options = {'title':'Favorite feature',
                       'width':400,
                       'height':300};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div_fav'));
        chart.draw(data, options);
      }
      
      function drawChartSpam() {

        // Create the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Feature');
        data.addColumn('number', 'Count');        
        
        {{ for f in spam: }}
        data.addRow([ '{{=f.feature}}' , {{=f.count}} ])
        {{pass}}
               
        // Set chart options
        var options = {'title':'Spam feature',
                       'width':400,
                       'height':300};

        // Instantiate and draw our chart, passing in some options.
        var chart = new google.visualization.PieChart(document.getElementById('chart_div_spam'));
        chart.draw(data, options);
      }
    
</script>      
<div  style='display: table;'>
    <div style="display: table-row">
        <div class='analytics'>
            <h5>Categories</h5>
            {{=SQLTABLE(category)}}
        </div>       
        <div id='chart_div_cat' style='display: table-cell'>
            <!-- google chart -->
        </div>
    </div>
    
    <hr/>
    <div style="display: table-row">
        <div class='analytics'>
            <h5>Favorite</h5>
            {{=SQLTABLE(fav)}}
        </div>       
        <div id='chart_div_fav' style='display: table-cell'>
            <!-- google chart -->
        </div>
    </div>
    
    <hr/>
    
    <!--  Second row -->
    <div style="display: table-row">
        <div class='analytics'>
            <h5>Spam</h5>
            {{=SQLTABLE(spam)}}
        </div>       
        <div id='chart_div_spam' style='display: table-cell'>
            <!-- google chart -->
        </div>
    </div>
    
</div>
